<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<h1>bingo security misroservice</h1>
<input type="button" value="获得订单信息" id="getOrderInfo"></input>
<input type="button" value="退出" id="logout"></input>
</body>
<script>
    authenication = false;
    $("#getOrderInfo").click(function(){
        $.ajax({
            url: "/api/order/get/1",
            type: "get",
            success: function (res) {
                console.log("获取成功！")},
            error: function (res) {
                if (res.status == 500 && res.message == 'refresh fail') {
                    window.location.href ='http://oauth.bingo.com:8080/logout?redirect_uri=http://admin.bingo.com:8083';
                }
            }
        })

    })
    $("#logout").click(function(){
        $.ajax({
            url: "/logout",
            success: function (res) {
                window.location.href ='http://oauth.bingo.com:8080/logout?redirect_uri=http://admin.bingo.com:8083';
            }
        })
    })

    $.ajax({
        url: "/me",
        success: function (res) {
            console.log(res)
            if(res){
                console.log("已经通过认证")
                authenication = true;
            }
            if(!authenication){
                console.log("未通过认证:"+authenication)
                window.location.href = 'http://oauth.bingo.com:8080/oauth/authorize?' +
                    'client_id=admin&' +
                    'redirect_uri=http://admin.bingo.com:8083/oauth/callback&'+
                    'response_type=code&' +
                    'state=abc'
            }
        }
    })
</script>
</html>